<template>
  <div class="icons">
    <swiper :options="swiperOption1" v-if="showIconList">
      <swiper-slide v-for='page of pages' :key='page.index'>
        <div class="icon" v-for="item of page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl">
          </div>
          <p class="icon_desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination swp2"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script type="text/javascript">
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption1: {
        pagination: '.swiper-pagination',
        paginationType: 'bullets'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    },
    showIconList () {
      return this.iconList.length
    }
  }
}
</script>

<style type="text/javastyle" lang="stylus" scoped>
@import '~styles/varibles.styl'
@import '~styles/mixins.styl'
.icons >>> .swiper-container
  overflow: visible
  height: 0
  padding-bottom: 50%
.icons
  margin-bottom: .2rem
  .icon
    position: relative
    width: 25%
    height: 0
    padding-bottom: 25%
    float: left
    .icon-img
      position: absolute
      top: 0
      left: 0
      right: 0
      bottom: .44rem
      //设置图标间距
      box-sizing: border-box
      padding: .2rem
      //设置间距结束
      .icon-img-content
        display: block
        margin: 0 auto
        padding-top: .1rem
        height: 100%
    .icon_desc
      position: absolute
      left: 0
      right: 0
      bottom: 0
      height: .44rem
      line-height: .44rem
      text-align: center
      color:$darkTextColor
      ellipsis()
  .swp2
    position: absolute
    bottom: 0
    color: #000
</style>
